<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>动态配置</title>
    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="<%=path%>/hplus/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="<%=path%>/hplus/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="<%=path%>/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">
     <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/hplus/js/plugins/sweetalert/sweetalert2.min.css">
</head>

<style type="text/css">
blockquote {
   border-left:0.4em solid #17B091;  
   font-size:18px;
   font-color:#333333;
}

span:hover{
    color: #17B091;
}

</style>

<body class="white-bg">
     <!-- 
    <div class="wrapper wrapper-content">
        <div class="col-sm-7"></div>
        <div class="col-sm-5" style="margin-top:0px;">
     
        	<div class="col-sm-10 text-right">
            <div class="input-group">
               <input type="text" placeholder="请填写模块名称" class="input form-control" id="modelName" >
               <div class="input-group-btn">  
                            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">  
                                <span class="caret"></span>  
                            </button>  
                            <ul class="dropdown-menu dropdown-menu-right" role="menu">  
                            </ul>  
               </div>  
             </div>
             </div>
             
            <div class="col-sm-2 text-left">
            <span class="input-group-btn">
                 <button type="button" class="btn btn btn-primary" onclick="search();"> <i class="fa fa-search"></i> 搜索</button>
            </span>
            </div>
        </div>
        </div>		
    -->
    
        <!-- 遍历出的二级菜单 -->
        <div style="margin-left:40px;" >			
        <div class="row" id="menuList">
        <!-- 该段内容需要动态填充begin -->	
        <!-- 
        <div class="col-sm-12" style="padding-left:0;">		
        <blockquote style="margin-top:28px;">品牌管理工作台</blockquote>
        </div>	
		 <div class="col-sm-3" style="padding-left:0;">
           <table class="table">
               <tbody>							
                    <tr>
                       <td class="project-status" style="border-top:0px;width:30%;">
                           <img src="<%=path%>/hplus/img/phone.png" />
                       </td>
                       <td class="project-title" style="border-top:0px;width:70%;">
                           <a href="" style="font-size:18px;color:#333333;" ><span>交易查询</span></a>
                           <br/>
                           <font style="font-size:14px;color:#999999;">查询交易详情</font> 
                        </td>
                     </tr>
               </tbody>
           </table>
     
        </div>
        
        <hr size="20" width="100%" color="#e7eaec" style="float:left"/>	
         -->
        <!-- 该段内容需要动态填充 end -->		
     </div>

    </div>

    <script src="<%=path%>/hplus/js/jquery.min.js?v=2.1.4"></script>
    <script src="<%=path%>/hplus/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="<%=path%>/hplus/js/plugins/jasny/jasny-bootstrap.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script src="<%=path%>/hplus/js/plugins/prettyfile/bootstrap-prettyfile.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
	<script src="${pageContext.request.contextPath}/hplus/js/plugins/sweetalert/sweetalert2.min.js"></script>
	<script src="<%=path%>/hplus/js/plugins/suggest/bootstrap-suggest.min.js"></script>
    <script type="text/javascript">

	
	var datas = [];
	
    //首次加载页面时，根据用户点击的一级菜单权限ID，从登陆用户角色对应的所有的权限中匹配其对应的二级菜单和分类，动态生成html
    $(function(){
    	searchModel('');
    });
    
    //查询模块
    function searchModel(searchMenuName){
    	//清空二级菜单
    	$("#menuList").html("");
    	//菜单ID
    	var menuId = GetQueryString("menuId");
    	
 		$.ajax({
            type: "POST",
            async: false,
            url: "${pageContext.request.contextPath}/login/ajaxAuthsInfo",
            data: {
            	"id":menuId
            	},
            dataType: "json",
      	    timeout: 1000,
            success: function(data){
            	var realData = data.data;
            	if(data.status == 200){
            		var menuTypes = new Array();
            		//1、循环出所有的级二菜单
            		for(var i=0;i<realData.length;i++){
            			if(realData[i].permissionLevel != null && realData[i].permissionLevel == 2 && realData[i].permissionLevel != ""){
            				menuTypes.push(realData[i]);
            			}
            		}
            		//如果是店员工作台			
/*             		if(menuId == 66){
            			var menuIdNoIndex = [];
            			for(var i=0;i<menuTypeRem.length;i++){					
            				if(menuTypeRem[i].indexOf('首页') == -1){
            					menuIdNoIndex.push(menuTypeRem[i]);
            				}
            			}
            			menuTypeRem = menuIdNoIndex;
            		} */
            		
					//1、循环二级菜单，将每一个三级菜单根据二级菜单进行分类
					for(var o=0;o<menuTypes.length;o++){
	            	//需要向div中追加的html
	            	var html = "";
					//2、将分类信息进行追加
					html += '<div class="col-sm-12" style="padding-left:0;">';
					html += '<blockquote style="margin-top:28px;color:#000000;">'+menuTypes[o].name+'</blockquote>';
					html += '</div>	';
            		//3、循环出每一个二级菜单，追加进对应的分类中
					for(var i=0;i<realData.length;i++){
						if(realData[i].parentCode == menuTypes[o].id){
						html += '<div class="col-sm-3" style="padding-left:0;">';
						html += '<table class="table">';
						html += '<tbody>';
						html += '<tr>';		
						html += '<td align="right" class="project-status" style="border-top:0px;width:30%;">';
						var account = "";
						var sign = "";
						if(typeof(GetQueryString("account"))=="undefined"){
							account = "";
						}else{
							account	= GetQueryString("account");				
						} 
							
						if(typeof(GetQueryString("sign"))=="undefined"){
							sign = "";
						}else{
							sign = GetQueryString("sign");
						} 
						if(realData[i].url.substring(0,1) == '/'){
							html += "<img src=\"<%=path%>/images/menuIcon/"+realData[i].menuIcon+"\" style=\"cursor:pointer\" onclick=\"menuPublic('"+realData[i].name+"','<%=path%>"+realData[i].url+"','"+realData[i].id+"');\"/>";
						}else if(realData[i].url.indexOf('crm.cecook.net') > -1 || realData[i].url.indexOf('.zhiweit.com') > -1 || realData[i].url.indexOf('crm.cecook.cn') > -1 ){
							html += "<img src=\"<%=path%>/images/menuIcon/"+realData[i].menuIcon+"\" style=\"cursor:pointer\" onclick=\"menuPublic('"+realData[i].name+"','"+realData[i].url+"account="+account+"&sign="+sign+"','"+realData[i].id+"');\"/>";
						}
						html += '</td>';
						html += '<td class="project-title" style="border-top:0px;width:70%;">';
						if(realData[i].url.substring(0,1) == '/'){
							html += "<a href='#' onclick=\"menuPublic('"+realData[i].name+"','<%=path%>"+realData[i].url+"','"+realData[i].id+"');\" style='font-size:18px;color:#000000;font-weight:500;' ><span>"+realData[i].name+"</span></a>";	
						}else if(realData[i].url.indexOf('crm.cecook.net') > -1 || realData[i].url.indexOf('.zhiweit.com') > -1 || realData[i].url.indexOf('crm.cecook.cn') > -1 ){
							html += "<a href='#' onclick=\"menuPublic('"+realData[i].name+"','"+realData[i].url+"account="+account+"&sign="+sign+"','"+realData[i].id+"');\" style='font-size:18px;color:#000000;font-weight:500;' ><span>"+realData[i].name+"</span></a>";	
						}
						html += '<br/>';
						html += '<font style="font-size:14px;color:#999999;">'+realData[i].menuDesc+'</font>';
						html += '</td>';
						html += '</tr>';
						html += '</tbody>';
						html += '</table>';
						html += '</div>';
						//alert(realData[i].url + "-----"+realData[i].name + "-----"+realData[i].id + "------" + realData[i].menuType + "-----" + realData[i].c);
						}
					}
					//4、将分割线进行追加
            		html += '<hr size="20" width="100%" color="#e7eaec" style="float:left"/>';
            		$("#menuList").append(html);
					}
            	}//else{
            	 //swal({text: "没有搜索到该菜单！",type: "warning"});
            	 //}	
            }
		});
    }
    
    
    //获取URL后的参数,解决乱码问题
	function GetQueryString(name) {   
	      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");   
	      var r = window.location.search.substr(1).match(reg);   
	      if (r != null) return decodeURI(r[2]); return null;   
	}  
    
    
	//点击增加选项卡公共方法
	function menuPublic(name,url,id){
  	    var modelName = "iframe"+id;
        var iframes = $("iframe[name^='iframe']", window.parent.document);	
    
        var olIframes = null;							
        for(var i = 0; i < iframes.length; i++) {
           if(modelName == iframes[i].name){
            	olIframes = iframes[i];		
            }
        }		
        if(olIframes == null){
   	  	 //将所有选中的样式清空
   	     $('.page-tabs-content', window.parent.document).html($('.page-tabs-content', window.parent.document).html().replace(/active/g,""));
   	  	 //为首部选项卡赋值
   	  	 $('.page-tabs-content', window.parent.document).append('<a id="tab'+id+'" href="javascript:;" class="active J_menuTab" data-id="'+url+'">'+name+' <i class="fa fa-times-circle"></i></a>');
   	  	 //将所有选项卡选项卡选中状态置为none，模糊匹配
   	  	 $("iframe[name^='iframe']", window.parent.document).css('display','none');		
   	  	 //动态增加选项卡iframe，并将选中状态设置为inline
   	  	 $('#content-main', window.parent.document).append('<iframe class="J_iframe" name="iframe'+id+'" src="'+url+'" style="display: inline;" data-id="'+url+'" seamless="" width="100%" height="100%" frameborder="0"></iframe>'); 
        }else{
      	  	//将所有选中的样式清空
      	    $('.page-tabs-content', window.parent.document).html($('.page-tabs-content', window.parent.document).html().replace(/active/g,""));
        	$("#tab"+id, window.parent.document).addClass("active");
      	  	//将所有选项卡选项卡选中状态置为none，模糊匹配
      	  	$("iframe[name^='iframe']", window.parent.document).css('display','none');		
      	    $("iframe[name='iframe"+id+"']", window.parent.document).css('display',' inline');
        }

	 }
	

    </script>
</body>
</html>
